package com.rescue.mapper;

import com.github.pagehelper.Page;
import com.rescue.forum.dto.UserCommentQueryDTO;
import com.rescue.forum.entity.ForumComment;
import com.rescue.forum.vo.CommentQueryVO;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface CommentMapper {
    @Select("select * from forum_comment where p_comment_id = #{commentId} and article_id = #{articleId}")
    Page<CommentQueryVO> getByPCommentIdT(Integer commentId, String articleId);

    @Select("select * from forum_comment where p_comment_id = #{commentId}")
    List<ForumComment> getByPCommentId(Integer commentId);

    /**
     * 根据评论批量删除
     *
     * @param idList
     */
    void deleteBatch(List<Integer> idList);


    //@Select("select * from forum_comment where comment_id = #{commentId}")
    ForumComment getById(Integer commentId);

    /**
     * 根据评论Id删除
     *
     * @param commentId
     */
    @Delete("delete from forum_comment where comment_id = #{commentId}")
    void deleteById(Integer commentId);

    /**
     * 审核评论
     *
     * @param commentId
     */
    @Update("update forum_comment set status = 1 where comment_id = #{commentId}")
    void auditComment(Integer commentId);

    /**
     * 删除某文章的评论
     *
     * @param articleId
     */
    @Delete("delete from forum_comment where article_id = #{articleId}")
    void deleteByArticleId(String articleId);

    Page<CommentQueryVO> getByPComment(int pCommentId, UserCommentQueryDTO userCommentQueryDTO);

    @Insert("insert into forum_comment (p_comment_id, article_id, content, img_path, user_id, nick_name, user_ip_address, reply_user_id, reply_nick_name,post_time, status) VALUE (#{pCommentId}, #{articleId}, #{content}, #{imgPath}, #{userId}, #{nickName}, #{userIpAddress}, #{replyUserId}, #{replyNickName},#{postTime}, #{status})")
    void save(ForumComment build);

    void update(ForumComment comment);

    @Select("select * from forum_comment where user_id = #{userId}")
    List<ForumComment> getByUserId(Integer userId);

    @Select("select count(*) from forum_comment where user_id = #{userId} and date (post_time) = #{date}")
    Integer getCommentCount(LocalDate date, Integer userId);

    @Select("select count(*) from forum_comment where user_id = #{userId} ")
    Integer getNumById(Integer userId);
}
